package org.unt.divers;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.zip.ZipFile;

import org.apache.log4j.Logger;
import org.unt.genlogic.Zips;

public class CheckJar {

	private static Logger log = Logger.getLogger(CheckJar.class
			.getCanonicalName());

	public static void main(String[] args) throws IOException {

		// checkBatch();
		checkEar();
	}

	public static void checkBatch() throws IOException {

		Map mapProd = Zips
				.getZipEntriesAsMap(new ZipFile(
						"C:/Speeder/Batchs/FRAP/Change 03 Feb. Add 6 weeks/batchJava_PROD.jar"));
		Map mapNew = Zips
				.getZipEntriesAsMap(new ZipFile(
						"C:/Speeder/Batchs/FRAP/Change 03 Feb. Add 6 weeks/batchJava.jar"));

		log.info("Amount files Prod \t" + mapProd.entrySet().size());
		log.info("Amount files New\t" + mapNew.entrySet().size() + "\n");

		for (Iterator iterator = mapProd.keySet().iterator(); iterator
				.hasNext();) {

			String name = (String) iterator.next();

			long value1 = ((Long) mapProd.get(name)).longValue();
			long value2 = ((Long) mapNew.get(name)).longValue();

			if (value1 != value2) {
				log.info(name + "\t" + value1 + "\t" + value2);
			}
		}
	}

	public static void checkEar() throws IOException {

		String baseDir1 = "C:/Speeder/Deploys/12.1/2012 05 22/ant/";
		String baseDir2 = "C:/Speeder/Deploys/12.1/2012 05 22/";

		Map map1 = new HashMap();
		Map map2 = new HashMap();

		String[] zips = { "SPD.ear", "SpdWeb.war", "SpdJava-1.0.3-SNAPSHOT.jar" };

		for (int i = 0; i < zips.length; i++) {

			Zips.getZipEntriesAsMap(new ZipFile(baseDir1 + zips[i]), map1);
			Zips.getZipEntriesAsMap(new ZipFile(baseDir2 + zips[i]), map2);
		}

		log.info("Amount files baseDir1 " + baseDir1 + "\t"
				+ map1.entrySet().size());
		log.info("Amount files baseDir2 " + baseDir2 + "\t"
				+ map2.entrySet().size() + "\n");

		for (Iterator iterator = map1.keySet().iterator(); iterator.hasNext();) {

			String name = (String) iterator.next();

			long value1 = ((Long) map1.get(name)).longValue();
			long value2 = ((Long) map2.get(name)).longValue();

			if (value1 != value2) {
				log.info(name + "\t" + value1 + "\t" + value2);
			}
		}
	}
}
